﻿@model int
@{
    int rating = Model == 0 ? 3 : Model;
    string fieldname = ViewData.TemplateInfo.HtmlFieldPrefix;
}
<input id="@fieldname" name="@fieldname" type="hidden" value="@rating" />
<ul class="rating">
    @for (int i = 1; i <= 5; i++)
    {
        if (i <= rating)
        {
        <li class="star" title="@i"></li>
        }
        else
        {
        <li class="star-disabled" title="@i"></li>   
        }
    }
</ul>
<script type="text/javascript">
    $(function () {
        $('ul.rating li').click(function () {
            var selectedIndex = $(this).index();
            $(this).parent().siblings('input[type="hidden"][name="@fieldname"]').val(selectedIndex + 1);
            @*$('#@fieldname').val(selectedIndex + 1);*@
                $(this).parent().find('li').each(function (index, Element) {
                    if (index > selectedIndex) {
                        $(Element).attr('class', 'star-disabled');
                    }
                    else {
                        $(Element).attr('class', 'star');
                    }
                });
            });
        });
</script>
